package student.dao;

import student.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author 嘉德罗斯
 * @date 2021/7/19
 */
public class StuDao {
    ArrayList<Student> list = new ArrayList<>();

    public void add(Student st) {
        list.add(st);
    }
    public void look() {
        System.out.println("id\t名字\t年龄\tsr");
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            System.out.println(s.getId()+"\t"+ s.getName() +"\t"+ s.getAge() +"\t"+ s.getBirthday());
        }
    }

    public boolean traverse(String  id) {
        for (int i = 0; i < list.size(); i++) {
                if (id.equals(list.get(i).getId())){
                    return false;
                }
        }
        return true;
    }
public boolean delete(String id){
        if(list.size() ==0){
            System.out.println("目前没有学生信息，请添加");
        }
    int index = -1;
    for (int i = 0; i < list.size(); i++) {
        if (id.equals(list.get(i).getId())){
            index = i;
        }
    }
        if (index == -1){
            return false;
        }else{
            list.remove(index);
            return true;
        }
    }
    public boolean sky(){
        if (list.size() ==0){
            System.out.println("目前还没有学生信息,请添加");
            return true;
            }
            return false;
    }

    public boolean amend(String idx) {
        if(list.size() ==0){
            System.out.println("目前没有学生信息，请添加");
        }
        int index = -1;
        for (int i = 0; i < list.size(); i++) {
            if (idx.equals(list.get(i).getId())){
                index = i;
            }
        }
        if (index == -1){
            return false;
        }else{
            Scanner sc =new Scanner(System.in);
            System.out.println("请输入学生姓名");
            String name = sc.next();
            list.get(index).setName(name);
            System.out.println("请输入学生年龄");
            String age = sc.next();
            list.get(index).setAge(age);
            System.out.println("请输入学生生日");
            String birthing = sc.next();
            list.get(index).setBirthday(birthing);
            return true;
        }
    }
}